<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	request.setAttribute("basePath",basePath);
%>
<%@ include file="/resources/js/easyui/taglibs.jsp"%>
<%@ include file="/resources/js/wechat/_wechatui.jsp"%>
<%@ include file="/resources/js/easyui/_viewJS.jsp"%>
<!DOCTYPE>
<html>
<head>
	<title>套餐</title>
</head>
<body>
<div class="loading"></div>
<!-- header -->
<header>
	<a href="javascript:history.go(-1);" class="top_fh">套餐编辑</a>
	<a href="JavaScript:;" class="top_add"></a>
</header>
<!-- header end -->

<div class="page">
	<div class="tcbj_inner">
		<form id="editform">
			<ul>
				<li>套餐编号：<span>${index}<input type="hidden" name="discountid" value="${discount.discountid}" /></span></li>
				<li>套餐名称：<span>${discount.discountname}</span></li>
				<li>套餐单价：<input type="text" class="money" name="money" id="money" value="${discount.money}" /></li>
				<li>套餐币数：<input type="text" class="coin" name="coin" id="coin" value="${discount.coin}" /></li>
			</ul>
			<div class="tcbj_button"><a href="JavaScript:;" id="editSubBtn">保存</a></div>
		</form>
	</div>
</div>

<!-- footer -->
<%@include file="/WEB-INF/jsp/wechat/_footer.jsp"%>
<!-- footer end -->

<!-- top加号弹窗 -->
<%@include file="/WEB-INF/jsp/wechat/_top.jsp"%>
<!-- top加号弹窗 end -->
</body>

<script type="application/javascript">
	function View(){
		var that = this;

		that.events = [
			{ sel : '#editSubBtn', act : 'click', func : 'editSub' }
		];

		that.editSub = function(){
			var money = $("#money").val();
			var coin = $("#coin").val();
			var reg = /^\+?[1-9][0-9]*$/;

			if(!reg.test(money)){
				alert("单价只能输入正整数,最长3位");
				return false;
			}else if(!reg.test(coin)){
				alert("币数只能输入正整数,最长3位");
				return false;
			}

			$.ajax({
				url:'${basePath}wechat/discount/edit',
				type : 'POST',
				data : $("#editform").serialize(),
				error: function (response) {
					ViewHelper.func.ajaxWechatErrorMessage(response);
				},
				success: function (ret) {
					if(ret.result) {
						window.location = "${basePath}wechat/discount/showView";
					}else{
						alert(ret.info);
					}
				}
			});

		};

		EventHandler.call(that, that.events);

		return that;
	}

	var view;

	$(function(){
		inherit(View, EventHandler);
		view = new View();
	});

	$(".money").long({"element":".money","action":"keyup","stringl":"0","stringls":"3","reg":/^[123456789]\d{0,9}$/,"stavalue":""});
	$(".coin").long({"element":".coin","action":"keyup","stringl":"0","stringls":"3","reg":/^[123456789]\d{0,9}$/,"stavalue":""});

</script>

</html>